package com.explment.lens.utils.result;

import lombok.Data;

import java.io.Serializable;
@Data
public class ResultData  implements Serializable {
    private int code;
    private String message;
    private Object data;
    private long timestamp;

    public static  ResultData success() {
        return new ResultData(ResultCode.SUCCESS);
    }

    public static  ResultData success(Object data) {
        return new ResultData(ResultCode.SUCCESS, data);
    }

    public static  ResultData fail(ResultCode code) {
        return new ResultData(code);
    }

    public static  ResultData fail(ResultCode code, String customMsg) {
        return new ResultData(code, customMsg);
    }

   public ResultData(ResultCode code) {
        this(code,null);
   }
    private ResultData(ResultCode code, Object data) {
        this.code = code.getCode();
        this.message = code.getMessage();
        this.data = data;
        this.timestamp = System.currentTimeMillis();
    }

    private ResultData(ResultCode code, String customMsg) {
        this.code = code.getCode();
        this.message = customMsg;
        this.timestamp = System.currentTimeMillis();
    }

}
